package be.bonamis.umpire.business.impl;

import java.math.BigDecimal;
import java.util.Arrays;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import be.bonamis.umpire.domain.notary.Barema;
import be.bonamis.umpire.domain.notary.BaremaSlice;
import be.bonamis.umpire.domain.notary.Slice;
import be.bonamis.umpire.repository.BaremaRepository;


@Service
public class BaremaService {

	@Autowired
	private BaremaRepository baremaRepository;

	@Transactional
	public void importData() {
		Barema baremaA = new Barema("A", true);
		
		Slice slice01 = new Slice(1, 7500);
		Slice slice02 = new Slice(2, 10000);
		Slice slice03 = new Slice(3, 12500);
		
		BaremaSlice baremaSlice = new BaremaSlice();
		baremaSlice.setBarema(baremaA);
		baremaSlice.setSlice(slice01);
		baremaSlice.setRate(new BigDecimal(0.25));
		BaremaSlice baremaSlice2 = new BaremaSlice();
		baremaSlice2.setBarema(baremaA);
		baremaSlice2.setSlice(slice02);
		baremaSlice2.setRate(new BigDecimal(0.20));
		BaremaSlice baremaSlice3 = new BaremaSlice();
		baremaSlice3.setBarema(baremaA);
		baremaSlice3.setSlice(slice03);
		baremaSlice3.setRate(new BigDecimal(0.15));
		
		baremaA.setSlices(Arrays.asList(baremaSlice,baremaSlice2, baremaSlice3));
		baremaRepository.save(baremaA);		
	}
}